<?php

namespace App\Http\Requests;

use Illuminate\Contracts\Validation\Validator;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\Exceptions\HttpResponseException;

class MechanismAuth extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'desc' => 'required',
            'name' => 'required',
            's_num' => 'required',
            'province_id' => 'required',
            'city_id' => 'required',
            'area_id' => 'required',
            'address' => 'required',
            'mobile' => 'required',
            'cert_img' => 'required',
            'cover' => 'required',
        ];
    }

    public function messages()
    {
        return [
            'desc.required' => '请输入公司/机构简介',
            'name.required' => '请输入公司名称',
            's_num.required' => '请输入企业税号',
            'province_id.required' => '请选择省',
            'city_id.required' => '请选择市',
            'area_id.required' => '请选择区',
            'address.required' => '请输入详细地址',
            'mobile.required' => '请输入联系电话',
            'cert_img.required' => '请上传证书',
            'cover.required' => '请上传经验图片',
        ];
    }

    protected function failedValidation(Validator $validator)
    {
        throw new HttpResponseException(response()->json([
            "code"  => 500,
            "msg"   => $validator->getMessageBag()->first(),
            "data"  => null,
        ], 200, [
            'Content-Type'=>'application/json; charset=UTF-8'
        ]));
    }
}
